package com.syx.commoncore.Model;

import com.syx.commoncore.enums.Resultcode;
import lombok.ToString;

@ToString
public class  Result<T> {
    private int code;
    private String message;
    private T data;

    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result() {
    }

    // Getter和Setter方法
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    // 静态方法
    public static Result success() {
        return new Result(Resultcode.SUCCESS.getCode(), Resultcode.SUCCESS.getMessage());
    }

    public static <T> Result success(T data) {
        return new Result(Resultcode.SUCCESS.getCode(), Resultcode.SUCCESS.getMessage(), data);
    }

    public static <T> Result success(String message, T data) {
        return new Result(Resultcode.SUCCESS.getCode(), message, data);
    }

   /* public static <T> Result success(String message) {
        return new Result(Resultcode.SUCCESS.getCode(), message);
    }*/

    /*
     * 失败
     */
    public static <T> Result failure(T data) {
        return new Result(Resultcode.FAILED.getCode(), Resultcode.FAILED.getMessage(), data);
    }

    public static <T> Result failure() {
        return new Result(Resultcode.FAILED.getCode(), Resultcode.FAILED.getMessage());
    }
    public static <T> Result failure(Resultcode resultcode){
        return new Result(resultcode.getCode(),resultcode.getMessage());


    }

    public static <T> Result failure(String message, T data) {
        return new Result(Resultcode.FAILED.getCode(), message, data);
    }

    public static <T> Result failure(String message) {
        return new Result(Resultcode.FAILED.getCode(), message);
    }
    public static <T> Result failure(int code,String message){
        return new Result(code,message);

    }
    public static <T> Result success(Resultcode resultcode){
        return new Result(resultcode.getCode(),resultcode.getMessage());


    }
}